package com.lablzh.gdxy.repository.course;

import com.lablzh.gdxy.entity.course.StudentCourse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;


public interface StudentCourseRepository extends JpaRepository<StudentCourse,Integer> {
    @Transactional

    void deleteByCourseIDAndStudentUsername(Integer courseID, String username);

    StudentCourse findByStudentUsernameAndCourseID(String studentUsername,Integer courseID);

    List<StudentCourse> findAllByStudentUsername(String username);

    List<StudentCourse> findAllByCourseID(Integer id);

    List<StudentCourse> findAllByCourseIDAndSummit(Integer id, String summit);

    List<StudentCourse> findAllByCourseIDAndReview(Integer id, String review);


    List<StudentCourse> findAllByStudentName(String studentName);

    List<StudentCourse> findAllByCollege(String college);

    List<StudentCourse> findAllByCollegeAndMajor(String college, String major);

    List<StudentCourse> findAllByCollegeAndMajorAndClasses(String college, String major, String classes);

    @Modifying
    @Transactional
    @Query("update StudentCourse set reportScore=?3,reportLevel=?4,note=?5,review=?6 where courseID=?1 and studentUsername=?2")
    void updateReportScoreAndReportLevelAndNoteAndReviewByCourseIDAndStudentUsername(Integer id, String studentUsername, Integer score, String level, String note, String review);

    @Transactional
    void deleteAllByCourseID(Integer id);
    @Modifying
    @Transactional
    @Query("update StudentCourse set review=?3 where courseID=?1 and studentUsername=?2")
    void updateReviewByIdAndStudentUsername(Integer id, String username,String review);
    @Modifying
    @Transactional
    @Query("update StudentCourse set reportName=?3,summitTime=?4 where courseID=?1 and studentUsername=?2")
    void updateReportNameAndSummitTimeByIdAndStudentUsername(Integer id, String username,String filename,LocalDate now);

    @Modifying
    @Transactional
    @Query("update StudentCourse set summit=?3,review=?4 where  courseID=?1 and studentUsername=?2")
    void updateSummitAndReviewByIdAndStudentUsername(Integer id, String username, String summit,String review);

    StudentCourse findByCourseIDAndStudentUsername(Integer id, String username);


    List<StudentCourse> findAllByStudentNameAndGrade(String studentName, String grade);

    List<StudentCourse> findAllByCollegeAndGrade(String college, String grade);

    List<StudentCourse> findAllByCollegeAndMajorAndGrade(String college, String major, String grade);

    List<StudentCourse> findAllByCollegeAndMajorAndClassesAndGrade(String college, String major, String classes, String grade);

}

